package jy.game.components.wuxue.box;


import java.util.ArrayList;
import java.util.List;

import jy.game.components.wuxue.JyBuff;
import jy.game.components.wuxue.JyTrigger;
import jy.game.components.wuxue.SkillCoverType;
import jy.game.components.wuxue.SkillCoverTypeHelper;
import jy.game.components.wuxue.SkillType0;
import jy.game.components.wuxue.pojo.JySkill;
import jy.game.components.wuxue.pojo.JyUniqueSkill;
import jy.game.tools.CommonSettings;
import jy.game.tools.JyColor;
import jy.game.tools.JyResourceManager;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.Root;

@Root(name = "skill")
public class JySkillInstance extends JySkillBox {

    //[XmlIgnore]
    @Attribute public int    level;
    @Attribute public int    Exp;
    @Attribute public String name;
    public  List<UniqueSkillInstance> UniqueSkills = new ArrayList<>();
    private String                    _name;


//    public JySkillInstance(String name, int level, int exp, int equipped) {
//        this._name = name;
//        this.Exp = exp;
//        this.level = level;
//        this.equipped = equipped;
//    }

    // (get) Token: 0x060004D7 RID: 1239 RVA: 0x00004917 File Offset: 0x00002B17
    // (set) Token: 0x060004D8 RID: 1240 RVA: 0x0000491F File Offset: 0x00002B1F


    void setName(String value) {
        this._name = value;
    }

//    public void refreshUniqueSkills() {
//        this.UniqueSkills.clear();
//        for (JyUniqueSkill skill : this.Skill().uniqueSkills) {
//            this.UniqueSkills.add(new UniqueSkillInstance(skill, this));
//        }
//    }

    // (get) Token: 0x060004DA RID: 1242 RVA: 0x00004928 File Offset: 0x00002B28
    public /*override*/ String Name() {
        {
            return this.name;
        }
    }

    // (get) Token: 0x060004DB RID: 1243 RVA: 0x00004930 File Offset: 0x00002B30
    public /*override*/ String Icon() {
        {
            return this.Skill().icon;
        }
    }

    // (get) Token: 0x060004DC RID: 1244 RVA: 0x0000493D File Offset: 0x00002B3D
    public /*override*/ JyColor Color() {
        {
            return JyColor.white;
        }
    }

    // (get) Token: 0x060004DD RID: 1245 RVA: 0x00004944 File Offset: 0x00002B44
    public /*override*/ int Cd() {
        {
            return this.Skill().getCoolDown(this.level);
        }
    }

    // (get) Token: 0x060004DE RID: 1246 RVA: 0x00004957 File Offset: 0x00002B57
    public /*override*/ int Type() {
        {
            return this.Skill().type;
        }
    }

    // (get) Token: 0x060004DF RID: 1247 RVA: 0x00004964 File Offset: 0x00002B64
    public /*override*/ int costMp() {
        {
            return new SkillCoverTypeHelper(this.coverType).CostMp(this.power(), this.size);
        }
    }

    // (get) Token: 0x060004E0 RID: 1248 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ int costBall() {
        {
            return 0;
        }
    }

    // (get) Token: 0x060004E1 RID: 1249 RVA: 0x00004982 File Offset: 0x00002B82
    public /*override*/ int castSize() {
        {
            return this.Skill().getCastSize(this.level);
        }
    }

    // (get) Token: 0x060004E2 RID: 1250 RVA: 0x00004995 File Offset: 0x00002B95
    public /*override*/ String animation() {
        {
            return this.Skill().getAnimationName(this.level);
        }
    }

    // (get) Token: 0x060004E3 RID: 1251 RVA: 0x00003D5C File Offset: 0x00001F5C
    public /*override*/ SkillType0 skillType() {
        {
            return SkillType0.Normal;
        }
    }

    // (get) Token: 0x060004E4 RID: 1252 RVA: 0x000049A8 File Offset: 0x00002BA8
    @Override public /*override*/ int level() {
        {
            return this.level;
        }
    }

    // (get) Token: 0x060004E5 RID: 1253 RVA: 0x000049B0 File Offset: 0x00002BB0
    @Override public /*override*/ boolean tiaohe() {
        {
            return this.Skill().getTiaohe();
        }
    }

    // (get) Token: 0x060004E6 RID: 1254 RVA: 0x000049BD File Offset: 0x00002BBD
    @Override public /*override*/ double suit() {
        {
            return this.Skill().suit;
        }
    }

    // (get) Token: 0x060004E7 RID: 1255 RVA: 0x000049CA File Offset: 0x00002BCA
    @Override public /*override*/ String audio() {
        {
            return this.Skill().audio;
        }
    }

    // (get) Token: 0x060004E8 RID: 1256 RVA: 0x00032094 File Offset: 0x00030294
    //[XmlIgnore]
    @Override protected /*override*/ String getDescriptionInRichtext(boolean forAchievement) {
        String text = "";
        text += this.Skill().info;
        text += "\n";
        if (forAchievement) {
            text += String.format("<color='black'>等级 %s/%s</color>\n", this.maxLevel(), CommonSettings.MAX_SKILL_LEVEL);

        } else {
            text += String.format("<color='black'>等级 %s/%s</color>\n", this.level(), this.maxLevel());
        }
        text += String.format("<color='black'>经验 %s/%s</color>\n", this.Exp, this.levelupExp());
        text += String.format("<color='red'>威力 %s</color>\n", this.power());
        text += String.format("<color='black'>覆盖类型 %s</color>\n", getSkillCoverTypeChinese());
        text += String.format("<color='black'>覆盖范围 %s</color>\n", this.size);
        text += String.format("<color='black'>施展范围 %s</color>\n", this.castSize);
        text += String.format("<color='cyan'>消耗内力 %s</color>\n", this.costMp);
        if (this.currentCd == 0) {
            text += String.format("<color='green'>技能CD %s/%s</color>\n", this.currentCd, this.Cd);
        } else {
            text += String.format("<color='red'>技能CD %s/%s</color>\n", this.currentCd, this.Cd);
        }
        if (this.tiaohe()) {
            text += "<color='green'>适性:阴阳调和</color>\n";
        } else if (this.suit() == 0) {
            text += "<color='black'>适性:无</color>\n";
        } else if (this.suit() > 0) {
            text += String.format("<color='yellow'>适性:阳%s%%</color>\n", this.Skill().suit * 100f);
        } else if (this.suit() < 0) {
            text += String.format("<color='cyan'>适性:阴%s%%</color>\n", -this.Skill().suit * 100f);
        }
        text += getBuffsString();
        if (this.Skill().triggers.size() > 0) {
            text += "\n\n 被动增益：\n";
            for (JyTrigger trigger : this.Skill().triggers) {
                if (this.level() < trigger.level) {
                    if (trigger.level <= this.maxLevel()) {
                        text += String.format("<color='red'>(×)(%s级解锁)%s</color>", trigger.ToString(), trigger.level);
                    } else {
                        text += String.format("<color='red'>(×)(%s级解锁)???</color>", trigger.level);
                    }
                } else {
                    text += String.format("<color='green'>(√)(%s级解锁)%s</color>", trigger, trigger.level);
                }
                text += "\n";
            }
        }
        return text;

    }

    // (get) Token: 0x060004E9 RID: 1257 RVA: 0x000049D7 File Offset: 0x00002BD7
    //[XmlIgnore]
    @Override public /*override*/ Iterable<JyBuff> getBuffs() {
        {
            return this.Skill().getBuffs();
        }
    }

    // (get) Token: 0x060004EA RID: 1258 RVA: 0x000323D4 File Offset: 0x000305D4
    @Override public /*override*/ double power() {
        {
            int num = 0;
            if (owner != null) {
                for (JyTrigger trigger : owner.GetTriggers("powerup_skill")) {
                    if (trigger.Argvs()[0].equals(this.Name)) {
                        num += Integer.parseInt(trigger.Argvs()[1]);
                    }
                }
            }
            return (double) Math.round(this.Skill().getPower(this.level) * (1.0 + (double) num / 100.0));
        }
    }

    // (get) Token: 0x060004EB RID: 1259 RVA: 0x000049E4 File Offset: 0x00002BE4
    public /*override*/ int Size() {
        {
            return this.Skill().getCoverSize(this.level);
        }
    }

    // (get) Token: 0x060004EC RID: 1260 RVA: 0x000049F7 File Offset: 0x00002BF7
    public /*override*/ SkillCoverType coverType() {
        {
            return this.Skill().getCoverType(this.level);
        }
    }

    // (get) Token: 0x060004ED RID: 1261 RVA: 0x00004A0A File Offset: 0x00002C0A
    public JySkill Skill() {
        return JyResourceManager.get(JySkill.class, this.name);

    }

    // (get) Token: 0x060004EE RID: 1262 RVA: 0x00004A17 File Offset: 0x00002C17
    //[XmlIgnore]
    public int levelupExp() {
        return this.Skill().getLevelupExp(this.level());
    }

    // (get) Token: 0x060004EF RID: 1263 RVA: 0x00004A2A File Offset: 0x00002C2A
    //[XmlIgnore]
    public int PreLevelupExp() {
        return this.Skill().getLevelupExp(this.level() - 1);
    }

    @Override public /*override*/ boolean tryAddExp(int exp, int maxLevel) {
//        exp += owner.AttributesFinal["wuxing"] / 30;
//        if (owner.hasTalent("武学奇才")) {
//            this.exp += exp * 2;
//        } else {
//            this.exp += exp;
//        }
//        boolean result = false;
//        int     num    = this.level;
//        if (maxLevel < 1) {
//            maxLevel = this.maxLevel();
//        } else {
//            maxLevel = Math.min(maxLevel, CommonSettings.MAX_SKILL_LEVEL);
//        }
//        while (this.exp >= this.levelupExp()) {
//            if (this.level() >= maxLevel) {
//                this.exp = this.levelupExp();
//                break;
//            }
//            this.exp -= this.levelupExp();
//            this.level++;
//            if (this.level > CommonSettings.MAX_SKILL_LEVEL) {
//                this.level = CommonSettings.MAX_SKILL_LEVEL;
//            }
//            result = true;
//        }
//        if (this.level > num) {
//            try {
//                RuntimeData.Instance.RefreshTeamMemberPanel(owner.key, false, true);
//            } catch (Exception e) {
//                // FileLogger.instance.LogException("JySkillInstance:294", e);
//            }
//        }
//        return result;
        return true;
    }
}
